{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import _pickle as cPickle"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 导入训练集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>location</th>\n",
       "      <th>age</th>\n",
       "      <th>item_id</th>\n",
       "      <th>rating</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>109814</th>\n",
       "      <td>27462</td>\n",
       "      <td>usa</td>\n",
       "      <td>0</td>\n",
       "      <td>1587492695</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>561359</th>\n",
       "      <td>137190</td>\n",
       "      <td>france</td>\n",
       "      <td>3</td>\n",
       "      <td>0552997234</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>182843</th>\n",
       "      <td>42721</td>\n",
       "      <td>canada</td>\n",
       "      <td>3</td>\n",
       "      <td>0671024108</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>854047</th>\n",
       "      <td>208829</td>\n",
       "      <td>canada</td>\n",
       "      <td>0</td>\n",
       "      <td>0140503897</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>559003</th>\n",
       "      <td>136348</td>\n",
       "      <td>usa</td>\n",
       "      <td>4</td>\n",
       "      <td>0807220299</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        user_id location  age     item_id  rating\n",
       "109814    27462      usa    0  1587492695       0\n",
       "561359   137190   france    3  0552997234       8\n",
       "182843    42721   canada    3  0671024108       8\n",
       "854047   208829   canada    0  0140503897       0\n",
       "559003   136348      usa    4  0807220299       9"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_data_training = cPickle.load(open('./data/df_data_training.pk1','rb'))\n",
    "df_data_training.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 344931 entries, 109814 to 473426\n",
      "Data columns (total 5 columns):\n",
      " #   Column    Non-Null Count   Dtype \n",
      "---  ------    --------------   ----- \n",
      " 0   user_id   344931 non-null  int64 \n",
      " 1   location  344931 non-null  object\n",
      " 2   age       344931 non-null  int64 \n",
      " 3   item_id   344931 non-null  object\n",
      " 4   rating    344931 non-null  int64 \n",
      "dtypes: int64(3), object(2)\n",
      "memory usage: 15.8+ MB\n"
     ]
    }
   ],
   "source": [
    "df_data_training.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['usa',\n",
       " 'canada',\n",
       " 'united kingdom',\n",
       " 'germany',\n",
       " '',\n",
       " 'australia',\n",
       " 'spain',\n",
       " 'france',\n",
       " 'n/a',\n",
       " 'italy',\n",
       " 'portugal']"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_data_training['location'].value_counts()[:11].index.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "top10_location = ['usa',\n",
    " 'canada',\n",
    " 'united kingdom',\n",
    " 'germany',\n",
    " 'australia',\n",
    " 'spain',\n",
    " 'france',\n",
    " 'n/a',\n",
    " 'italy',\n",
    " 'portugal']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_data_training['location'] = df_data_training['location'].apply(lambda location:location if location in top10_location else 'other')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "usa               230427\n",
       "canada             31331\n",
       "other              25235\n",
       "united kingdom     15239\n",
       "germany            11986\n",
       "australia           7873\n",
       "spain               7792\n",
       "france              4142\n",
       "n/a                 4097\n",
       "italy               3665\n",
       "portugal            3144\n",
       "Name: location, dtype: int64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_data_training['location'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "feature_recommand = {\n",
    "    'usa':{\n",
    "        '0':[item1,item2,item3],\n",
    "        '1':[item1,item2,item3]\n",
    "    },\n",
    "    'canada':{\n",
    "        '0':[item1,item2,item3],\n",
    "        '1':[item1,item2,item3]\n",
    "    },\n",
    "}\n",
    "feature_recommand_with_rating = {\n",
    "    'usa':{\n",
    "        '0':[{item1:10.0},{item2:9.7},item3],\n",
    "        '1':[item1,item2,item3]\n",
    "    },\n",
    "    'canada':{\n",
    "        '0':[item1,item2,item3],\n",
    "        '1':[item1,item2,item3]\n",
    "    },\n",
    "}\n",
    "\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import defaultdict\n",
    "# feature_recommend = defaultedict(dict)\n",
    "# feature_recommand[1]\n",
    "# feature_recommand[1] = 'a'\n",
    "# print(feature_recommand[1])\n",
    "#feature_recommand['usa'][0]=[1,2,3,4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "feature_recommand = defaultdict(dict)\n",
    "feature_recommand_with_rating = defaultdict(dict)\n",
    "\n",
    "for location,groupby_location in df_data_training.groupby('location'):\n",
    "    for age,groupby_location_age in groupby_location.groupby('age'):\n",
    "        item_id_value_counts = groupby_location_age['item_id'].value_counts()\n",
    "        divide_boundary = max(np.percentile(item_id_value_counts,75),5)\n",
    "        groupby_location_age_top = groupby_location_age[\n",
    "            groupby_location_age['item_id'].isin(\n",
    "            item_id_value_counts[item_id_value_counts >= divide_boundary].index\n",
    "        )]\n",
    "        item_mean_rating = groupby_location_age_top.groupby('item_id')['rating'].mean().sort_values(ascending = False)\n",
    "        feature_recommand[location][age]=[\n",
    "            item_id\n",
    "            for item_id in item_mean_rating.index if item_mean_rating[item_id]>=5\n",
    "        ]\n",
    "        feature_recommand_with_rating[location][age]=[\n",
    "            {\"%s\" % item_id:round(item_mean_rating[item_id],2)}\n",
    "            for item_id in item_mean_rating.index if item_mean_rating[item_id]>=5\n",
    "        ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "defaultdict(dict,\n",
       "            {'australia': {0: [], 1: [], 2: [], 3: [], 4: [], 5: []},\n",
       "             'canada': {0: ['0440215625',\n",
       "               '0060928336',\n",
       "               '0812511816',\n",
       "               '0140293248',\n",
       "               '0676973779',\n",
       "               '0312291639',\n",
       "               '0156007754',\n",
       "               '0375727345',\n",
       "               '0316601950',\n",
       "               '0440226430'],\n",
       "              1: [],\n",
       "              2: [],\n",
       "              3: ['0679781587',\n",
       "               '0553578685',\n",
       "               '0553296981',\n",
       "               '0671011375',\n",
       "               '0676974805',\n",
       "               '0770422632',\n",
       "               '0684874350',\n",
       "               '0312924585',\n",
       "               '0385484518',\n",
       "               '0451155750',\n",
       "               '0385730586',\n",
       "               '0743436210',\n",
       "               '0440211727',\n",
       "               '034538475X',\n",
       "               '0394223802',\n",
       "               '059035342X',\n",
       "               '0060987561',\n",
       "               '0385335881',\n",
       "               '0345313860',\n",
       "               '0671021001',\n",
       "               '0330267388',\n",
       "               '0553572997',\n",
       "               '0064400018',\n",
       "               '0140067477'],\n",
       "              4: [],\n",
       "              5: []},\n",
       "             'france': {0: [],\n",
       "              2: [],\n",
       "              3: ['2070360024',\n",
       "               '2253033138',\n",
       "               '225313922X',\n",
       "               '2253005274',\n",
       "               '2253150711',\n",
       "               '2070408507',\n",
       "               '2070394727',\n",
       "               '202025462X',\n",
       "               '2253140503'],\n",
       "              4: [],\n",
       "              5: []},\n",
       "             'germany': {0: ['3596144868', '3423105410', '3257229534'],\n",
       "              1: [],\n",
       "              2: [],\n",
       "              3: ['3423204206',\n",
       "               '3442414199',\n",
       "               '3423011505',\n",
       "               '3518368540',\n",
       "               '3150000017',\n",
       "               '3499224623',\n",
       "               '3453210697',\n",
       "               '3453007867',\n",
       "               '3492222463',\n",
       "               '3453071174',\n",
       "               '3404148665',\n",
       "               '3442439736',\n",
       "               '3423084049'],\n",
       "              4: [],\n",
       "              5: []},\n",
       "             'italy': {0: ['8826703132', '8804342838'],\n",
       "              2: [],\n",
       "              3: ['8817106100', '8804390727'],\n",
       "              4: []},\n",
       "             'n/a': {0: []},\n",
       "             'other': {0: ['0446310786',\n",
       "               '059035342X',\n",
       "               '067976402X',\n",
       "               '0440226430'],\n",
       "              1: [],\n",
       "              2: [],\n",
       "              3: ['0439064864',\n",
       "               '0439136369',\n",
       "               '0140620338',\n",
       "               '043935806X',\n",
       "               '0060987103',\n",
       "               '0441000916',\n",
       "               '0385504209',\n",
       "               '0439139600',\n",
       "               '0070212570',\n",
       "               '0062502182',\n",
       "               '034538475X',\n",
       "               '0425152251',\n",
       "               '0552142379',\n",
       "               '0060930535',\n",
       "               '0385498802'],\n",
       "              4: [],\n",
       "              5: []},\n",
       "             'portugal': {0: [],\n",
       "              2: [],\n",
       "              3: ['9726106141', '9727722458'],\n",
       "              4: [],\n",
       "              5: []},\n",
       "             'spain': {0: [],\n",
       "              2: [],\n",
       "              3: ['8445071777',\n",
       "               '846630679X',\n",
       "               '8445071416',\n",
       "               '8423309835',\n",
       "               '8483101610',\n",
       "               '840149186X',\n",
       "               '0060510323',\n",
       "               '0316666343',\n",
       "               '8420725927',\n",
       "               '8420441708',\n",
       "               '0553274503',\n",
       "               '8495618605'],\n",
       "              4: [],\n",
       "              5: []},\n",
       "             'united kingdom': {0: ['0749397543',\n",
       "               '0552996009',\n",
       "               '0330367358',\n",
       "               '0099771519'],\n",
       "              1: [],\n",
       "              2: [],\n",
       "              3: ['0749391308',\n",
       "               '1844262553',\n",
       "               '0786867647',\n",
       "               '0007110928',\n",
       "               '0140279288',\n",
       "               '000649840X',\n",
       "               '0575400951',\n",
       "               '0749305401',\n",
       "               '0330262130',\n",
       "               '1853261580',\n",
       "               '0552134643',\n",
       "               '0749309423',\n",
       "               '0060392452',\n",
       "               '0552996009',\n",
       "               '034911675X',\n",
       "               '0552131067',\n",
       "               '0552140295',\n",
       "               '0552124753',\n",
       "               '0099747200',\n",
       "               '0552142352',\n",
       "               '1860461670',\n",
       "               '0156027321'],\n",
       "              4: [],\n",
       "              5: []},\n",
       "             'usa': {0: ['0393312836',\n",
       "               '0375400117',\n",
       "               '0312265840',\n",
       "               '006104444X',\n",
       "               '0767903382',\n",
       "               '0439064864',\n",
       "               '0688170528',\n",
       "               '0517122707',\n",
       "               '0425174484',\n",
       "               '0805019359',\n",
       "               '0887307876',\n",
       "               '0740704818',\n",
       "               '0440215625',\n",
       "               '0671705091',\n",
       "               '0440235502',\n",
       "               '0679723161',\n",
       "               '0439136350',\n",
       "               '014100018X',\n",
       "               '0449911519',\n",
       "               '0525946233',\n",
       "               '0689710682',\n",
       "               '0385318073',\n",
       "               '0684826976',\n",
       "               '0345310020',\n",
       "               '0061000027',\n",
       "               '0316182540',\n",
       "               '0316154059',\n",
       "               '0553571656',\n",
       "               '0590353403',\n",
       "               '0671776134',\n",
       "               '0671026011',\n",
       "               '042516828X',\n",
       "               '0671014188',\n",
       "               '0316779490',\n",
       "               '0684801051',\n",
       "               '0440127793',\n",
       "               '0743227441',\n",
       "               '0679426159',\n",
       "               '0440439884',\n",
       "               '0385510438',\n",
       "               '0805063889',\n",
       "               '0440414857',\n",
       "               '0451191153',\n",
       "               '0380702843',\n",
       "               '0786808551',\n",
       "               '0385472943',\n",
       "               '0553284118',\n",
       "               '0446391301',\n",
       "               '1558744630',\n",
       "               '0670894605',\n",
       "               '0446519138',\n",
       "               '0441627404',\n",
       "               '0440236169',\n",
       "               '0375411550',\n",
       "               '0060096195',\n",
       "               '0440110653',\n",
       "               '1573229083',\n",
       "               '0446670251',\n",
       "               '0345339681',\n",
       "               '0451204530',\n",
       "               '0156005891',\n",
       "               '0440219078',\n",
       "               '043935806X',\n",
       "               '0345436911',\n",
       "               '038533558X',\n",
       "               '0743467523',\n",
       "               '0553550039',\n",
       "               '0486270629',\n",
       "               '0671727796',\n",
       "               '0142001430',\n",
       "               '0156711427',\n",
       "               '0380730820',\n",
       "               '0812570944',\n",
       "               '0679734775',\n",
       "               '0156007754',\n",
       "               '0385472951',\n",
       "               '0140042520',\n",
       "               '0141301155',\n",
       "               '0399148450',\n",
       "               '0345430573',\n",
       "               '0061092177',\n",
       "               '0767905385',\n",
       "               '0140177396',\n",
       "               '0671693816',\n",
       "               '0743211235',\n",
       "               '0446670111',\n",
       "               '0064401847',\n",
       "               '0060959037',\n",
       "               '0312966970',\n",
       "               '0385720955',\n",
       "               '0553375407',\n",
       "               '0312099436',\n",
       "               '0345435796',\n",
       "               '0439139597',\n",
       "               '0385420161',\n",
       "               '0310209307',\n",
       "               '0312421273',\n",
       "               '0064400042',\n",
       "               '0142004235',\n",
       "               '0440967694',\n",
       "               '034541389X',\n",
       "               '0375506276',\n",
       "               '0671016776',\n",
       "               '055357258X',\n",
       "               '0440236053',\n",
       "               '0786868716',\n",
       "               '0345348036',\n",
       "               '068484477X',\n",
       "               '0515132020',\n",
       "               '0553291955',\n",
       "               '0380001411',\n",
       "               '055310666X',\n",
       "               '0786889608',\n",
       "               '0446611085',\n",
       "               '0316678104',\n",
       "               '067162461X',\n",
       "               '0312971842',\n",
       "               '0345369947',\n",
       "               '0440343194',\n",
       "               '0060922249',\n",
       "               '0688177867',\n",
       "               '0399146253',\n",
       "               '0345413350',\n",
       "               '0553107305',\n",
       "               '0375500510',\n",
       "               '0064471101',\n",
       "               '0440204194',\n",
       "               '0312205406',\n",
       "               '039914465X',\n",
       "               '0061093335',\n",
       "               '0743411269',\n",
       "               '0446520802',\n",
       "               '0451191145',\n",
       "               '0446359866',\n",
       "               '0515131210',\n",
       "               '0142000361',\n",
       "               '081297106X',\n",
       "               '0486284999',\n",
       "               '0553292722',\n",
       "               '0805062971',\n",
       "               '0767903579',\n",
       "               '0312990456',\n",
       "               '0842329250',\n",
       "               '0553573926',\n",
       "               '0345423135',\n",
       "               '0440166497',\n",
       "               '067091021X',\n",
       "               '0740723367',\n",
       "               '0399150897',\n",
       "               '0590371258',\n",
       "               '0684195984',\n",
       "               '0380820846',\n",
       "               '0553583611',\n",
       "               '0842329218',\n",
       "               '0449005615',\n",
       "               '0312275420',\n",
       "               '0684803968',\n",
       "               '055314300X',\n",
       "               '0451524934',\n",
       "               '0684801523',\n",
       "               '0446527033',\n",
       "               '0515128554',\n",
       "               '0345417976',\n",
       "               '0380792745',\n",
       "               '0345433491',\n",
       "               '0425179885',\n",
       "               '1558743669',\n",
       "               '0553582127',\n",
       "               '0312195516',\n",
       "               '0515130966',\n",
       "               '0679781587',\n",
       "               '0060930535',\n",
       "               '0385721420',\n",
       "               '0826308791',\n",
       "               '0452269571',\n",
       "               '0743437802',\n",
       "               '0380717018',\n",
       "               '0515131229',\n",
       "               '006440630X',\n",
       "               '0440223016',\n",
       "               '0553575104',\n",
       "               '055321330X',\n",
       "               '0440224594',\n",
       "               '0743204077',\n",
       "               '0345404793',\n",
       "               '0060964049',\n",
       "               '0446677450',\n",
       "               '0399134409',\n",
       "               '0061020400',\n",
       "               '0865471185',\n",
       "               '0380721643',\n",
       "               '0671729411',\n",
       "               '0515132187',\n",
       "               '0060987103',\n",
       "               '0316666343',\n",
       "               '0439136369',\n",
       "               '0316969680',\n",
       "               '0151008116',\n",
       "               '0345416260',\n",
       "               '059035342X',\n",
       "               '0385722206',\n",
       "               '0553289691',\n",
       "               '0061097314',\n",
       "               '0452281725',\n",
       "               '0060914653',\n",
       "               '0446531332',\n",
       "               '0140254544',\n",
       "               '0312966091',\n",
       "               '0553272535',\n",
       "               '155874262X',\n",
       "               '0316089699',\n",
       "               '0679736042',\n",
       "               '0553574639',\n",
       "               '0679457313',\n",
       "               '0425163385',\n",
       "               '0316789844',\n",
       "               '0140185216',\n",
       "               '0425182878',\n",
       "               '0316602906',\n",
       "               '0345342968',\n",
       "               '044023512X',\n",
       "               '0345339738',\n",
       "               '0786863986',\n",
       "               '0345384369',\n",
       "               '0399150439',\n",
       "               '1551665301',\n",
       "               '0451149513',\n",
       "               '0425081818',\n",
       "               '0786819146',\n",
       "               '0842329277',\n",
       "               '0345348109',\n",
       "               '0060936363',\n",
       "               '080411935X',\n",
       "               '0807083054',\n",
       "               '0440212723',\n",
       "               '0446525537',\n",
       "               '0060392452',\n",
       "               '0425107469'],\n",
       "              1: [],\n",
       "              2: ['0380778556',\n",
       "               '0439064864',\n",
       "               '0345339681',\n",
       "               '0394820371',\n",
       "               '0812550706',\n",
       "               '0440229499',\n",
       "               '0446310786',\n",
       "               '0064407055',\n",
       "               '0345339703',\n",
       "               '0440498058',\n",
       "               '0064472795',\n",
       "               '0142000981',\n",
       "               '0440219078'],\n",
       "              3: ['0553213695',\n",
       "               '0345352661',\n",
       "               '0515134481',\n",
       "               '0811802981',\n",
       "               '140003180X',\n",
       "               '0345384210',\n",
       "               '0449232921',\n",
       "               '0345450892',\n",
       "               '0439425220',\n",
       "               '0836218787',\n",
       "               '0743411358',\n",
       "               '0345322231',\n",
       "               '0446677450',\n",
       "               '0451191137',\n",
       "               '0525946284',\n",
       "               '0553294385',\n",
       "               '0385199570',\n",
       "               '0064407691',\n",
       "               '0684801221',\n",
       "               '034543014X',\n",
       "               '042507160X',\n",
       "               '0440904196',\n",
       "               '0670835382',\n",
       "               '0452274427',\n",
       "               '0374525641',\n",
       "               '0553348981',\n",
       "               '0060248025',\n",
       "               '0451167716',\n",
       "               '0060256672',\n",
       "               '0758200862',\n",
       "               '0671722859',\n",
       "               '0590353403',\n",
       "               '0385335679',\n",
       "               '0553379011',\n",
       "               '0836218981',\n",
       "               '0440158532',\n",
       "               '0836218051',\n",
       "               '0316693294',\n",
       "               '0836218353',\n",
       "               '0345335465',\n",
       "               '0385482388',\n",
       "               '0140185232',\n",
       "               '0060254920',\n",
       "               '0385315031',\n",
       "               '0743424107',\n",
       "               '059030271X',\n",
       "               '0440222028',\n",
       "               '0451456718',\n",
       "               '0875421180',\n",
       "               '0440343194',\n",
       "               '1558506462',\n",
       "               '0373802021',\n",
       "               '0440220653',\n",
       "               '0590371258',\n",
       "               '0140258795',\n",
       "               '0553283685',\n",
       "               '0446601977',\n",
       "               '0060175966',\n",
       "               '0767905172',\n",
       "               '0679879250',\n",
       "               '0505523892',\n",
       "               '038542471X',\n",
       "               '0553379658',\n",
       "               '0446353957',\n",
       "               '0060809833',\n",
       "               '0812533054',\n",
       "               '0393312836',\n",
       "               '0380718758',\n",
       "               '038533348X',\n",
       "               '0440401585',\n",
       "               '055321330X',\n",
       "               '0060096195',\n",
       "               '0448060191',\n",
       "               '1400032717',\n",
       "               '0312050631',\n",
       "               '0441172717',\n",
       "               '0316899992',\n",
       "               '0743247612',\n",
       "               '0842332286',\n",
       "               '0375701214',\n",
       "               '0373250223',\n",
       "               '0553573314',\n",
       "               '0439064864',\n",
       "               '0393312801',\n",
       "               '0425182878',\n",
       "               '0140282033',\n",
       "               '0671744577',\n",
       "               '0679459618',\n",
       "               '051770739X',\n",
       "               '0064471055',\n",
       "               '038548951X',\n",
       "               '043936213X',\n",
       "               '0373872127',\n",
       "               '0679775439',\n",
       "               '0425129586',\n",
       "               '0451210158',\n",
       "               '039914787X',\n",
       "               '0812575717',\n",
       "               '043935806X',\n",
       "               '0812550706',\n",
       "               '0439139597',\n",
       "               '0439136369',\n",
       "               '0441008615',\n",
       "               '0517693119',\n",
       "               '0743211383',\n",
       "               '0385729332',\n",
       "               '0446600253',\n",
       "               '084233226X',\n",
       "               '0553289691',\n",
       "               '0553380958',\n",
       "               '0671034006',\n",
       "               '0380752859',\n",
       "               '0060935464',\n",
       "               '0441005748',\n",
       "               '052594527X',\n",
       "               '0064471063',\n",
       "               '0451526341',\n",
       "               '0312423799',\n",
       "               '0252006860',\n",
       "               '0380752867',\n",
       "               '0451169514',\n",
       "               '0671250671',\n",
       "               '0765342987',\n",
       "               '0380753014',\n",
       "               '0451197364',\n",
       "               '0345318854',\n",
       "               '0446527033',\n",
       "               '0451166361',\n",
       "               '0425130215',\n",
       "               '0380802325',\n",
       "               '0670813028',\n",
       "               '0842329277',\n",
       "               '0451526562',\n",
       "               '0345347536',\n",
       "               '0142000221',\n",
       "               '0451523350',\n",
       "               '0060934913',\n",
       "               '0385474547',\n",
       "               '0553242954',\n",
       "               '0618002219',\n",
       "               '1592400876',\n",
       "               '006017143X',\n",
       "               '0836213319',\n",
       "               '0441790348',\n",
       "               '0743437802',\n",
       "               '037541309X',\n",
       "               '0439136350',\n",
       "               '0393050939',\n",
       "               '0064401847',\n",
       "               '0156528207',\n",
       "               '0451207521',\n",
       "               '0553573985',\n",
       "               '034530988X',\n",
       "               '0446352764',\n",
       "               '0515133086',\n",
       "               '0451408462',\n",
       "               '0380729342',\n",
       "               '0767902513',\n",
       "               '0886773784',\n",
       "               '0312990456',\n",
       "               '0590406205',\n",
       "               '0316153990',\n",
       "               '0316107352',\n",
       "               '0393317552',\n",
       "               '0385421982',\n",
       "               '0553268449',\n",
       "               '0553375407',\n",
       "               '0375506039',\n",
       "               '0394820371',\n",
       "               '0671746065',\n",
       "               '0452279178',\n",
       "               '0399145990',\n",
       "               '0156005891',\n",
       "               '0345442822',\n",
       "               '0395977894',\n",
       "               '0553262580',\n",
       "               '0060981180',\n",
       "               '051513175X',\n",
       "               '0618129022',\n",
       "               '0380716542',\n",
       "               '0375400117',\n",
       "               '0380001411',\n",
       "               '0441007147',\n",
       "               '0140374248',\n",
       "               '0679805273',\n",
       "               '0399148248',\n",
       "               '0440431808',\n",
       "               '0060507845',\n",
       "               '0373250274',\n",
       "               '1558746099',\n",
       "               '1579546463',\n",
       "               '0060234814',\n",
       "               '0345272587',\n",
       "               '1573222259',\n",
       "               '034543739X',\n",
       "               '0060927569',\n",
       "               '0345301870',\n",
       "               '0743225082',\n",
       "               '0140143505',\n",
       "               '0451524934',\n",
       "               '0446391301',\n",
       "               '0805062971',\n",
       "               '1880418568',\n",
       "               '0345409469',\n",
       "               '0345366239',\n",
       "               '0515135216',\n",
       "               '1853260010',\n",
       "               '0394558235',\n",
       "               '0385335180',\n",
       "               '0671025341',\n",
       "               '0553208845',\n",
       "               '0316182540',\n",
       "               '1931561648',\n",
       "               '0316769509',\n",
       "               '0670839531',\n",
       "               '051511779X',\n",
       "               '0375725849',\n",
       "               '0380709562',\n",
       "               '0670272663',\n",
       "               '0312962452',\n",
       "               '0440901588',\n",
       "               '0425188361',\n",
       "               '0804108412',\n",
       "               '0684818868',\n",
       "               '0778320480',\n",
       "               '014017737X',\n",
       "               '0874778883',\n",
       "               '0671776096',\n",
       "               '0060930934',\n",
       "               '0140133488',\n",
       "               '0380868768',\n",
       "               '0452272319',\n",
       "               '0843948507',\n",
       "               '0679410325',\n",
       "               '0671742558',\n",
       "               '0374199698',\n",
       "               '0877017883',\n",
       "               '0446520802',\n",
       "               '0688170528',\n",
       "               '0060391626',\n",
       "               '084232920X',\n",
       "               '0316666009',\n",
       "               '0618526412',\n",
       "               '0515103292',\n",
       "               '0441001971',\n",
       "               '0440226686',\n",
       "               '0440145465',\n",
       "               '0671415085',\n",
       "               '0451163966',\n",
       "               '0446310786',\n",
       "               '0553575023',\n",
       "               '0425179672',\n",
       "               '0553571583',\n",
       "               '0446532452',\n",
       "               '0394800133',\n",
       "               '068487217X',\n",
       "               '0553210793',\n",
       "               '039480001X',\n",
       "               '0385418493',\n",
       "               '0553573861',\n",
       "               '0671461494',\n",
       "               '0451524667',\n",
       "               '0836220498',\n",
       "               '0312274920',\n",
       "               '038531258X',\n",
       "               '0060929790',\n",
       "               '0374270325',\n",
       "               '0425105334',\n",
       "               '0805063889',\n",
       "               '0312422156',\n",
       "               '0373196636',\n",
       "               '0345260791',\n",
       "               '0060256737',\n",
       "               '044021985X',\n",
       "               '0812532635',\n",
       "               '0520204956',\n",
       "               '0811811409',\n",
       "               '1878424319',\n",
       "               '067102535X',\n",
       "               '0671496174',\n",
       "               '1551668017',\n",
       "               '0425152499',\n",
       "               '140005446X',\n",
       "               '075820230X',\n",
       "               '0802138004',\n",
       "               '0553582909',\n",
       "               '0060557257',\n",
       "               '1573229083',\n",
       "               '0765343436',\n",
       "               '0553210416',\n",
       "               '0345334310',\n",
       "               '0373833458',\n",
       "               '0451165209',\n",
       "               '067165831X',\n",
       "               '0440405483',\n",
       "               '038073186X',\n",
       "               '0060096209',\n",
       "               '0670892742',\n",
       "               '0684802988',\n",
       "               '0679426140',\n",
       "               '014038572X',\n",
       "               '1558744630',\n",
       "               '0062502174',\n",
       "               '0440229499',\n",
       "               '0451525884',\n",
       "               '0345442768',\n",
       "               '0449219461',\n",
       "               '0316143464',\n",
       "               '0743206029',\n",
       "               '0375756981',\n",
       "               '0446603422',\n",
       "               '0451628039',\n",
       "               '076790382X',\n",
       "               '0399143947',\n",
       "               '0441004520',\n",
       "               '0140042598',\n",
       "               '0802130208',\n",
       "               '0345339703',\n",
       "               '0380756293',\n",
       "               '0373790651',\n",
       "               '067187750X',\n",
       "               '0385490445',\n",
       "               '0375507493',\n",
       "               '0345305183',\n",
       "               '0345358805',\n",
       "               '0756400619',\n",
       "               '0380816555',\n",
       "               '0679729798',\n",
       "               '0671733893',\n",
       "               '0671729454',\n",
       "               '076791404X',\n",
       "               '0425101452',\n",
       "               '0671640453',\n",
       "               '0425181111',\n",
       "               '0671702513',\n",
       "               '0553258524',\n",
       "               '0440224721',\n",
       "               '0505523752',\n",
       "               '0446516317',\n",
       "               '0451160916',\n",
       "               '0451162072',\n",
       "               '0312289510',\n",
       "               '0886777631',\n",
       "               '0891075275',\n",
       "               '0932379516',\n",
       "               '0066212855',\n",
       "               '140003339X',\n",
       "               '0812544501',\n",
       "               '0553572490',\n",
       "               '0451523024',\n",
       "               '0452279488',\n",
       "               '0553373803',\n",
       "               '0440487617',\n",
       "               '1573229628',\n",
       "               '0812510992',\n",
       "               '0553258559',\n",
       "               '006000438X',\n",
       "               '0553211765',\n",
       "               '0440241413',\n",
       "               '0843949945',\n",
       "               '0515127396',\n",
       "               '0517580497'],\n",
       "              4: ['0670894605',\n",
       "               '080411935X',\n",
       "               '0671038184',\n",
       "               '0553250531',\n",
       "               '0142001430',\n",
       "               '0425166929',\n",
       "               '0671042262',\n",
       "               '0451197038',\n",
       "               '0316153915',\n",
       "               '0385505833',\n",
       "               '0743227441',\n",
       "               '0451207521',\n",
       "               '0385420161',\n",
       "               '0553574574',\n",
       "               '0449005615',\n",
       "               '0375412530',\n",
       "               '038572179X',\n",
       "               '0316603287',\n",
       "               '039592720X',\n",
       "               '0743486226',\n",
       "               '0553287346',\n",
       "               '0345362721',\n",
       "               '0385490992',\n",
       "               '0515136530',\n",
       "               '0553580221',\n",
       "               '0064400557',\n",
       "               '039914563X',\n",
       "               '0345384350',\n",
       "               '0446611921',\n",
       "               '1558745017',\n",
       "               '0385503822',\n",
       "               '0515131083',\n",
       "               '0142004235',\n",
       "               '0515136557',\n",
       "               '0525947299',\n",
       "               '0446667900',\n",
       "               '0874776945',\n",
       "               '0679425268',\n",
       "               '0439064872',\n",
       "               '0553801929',\n",
       "               '0439136350',\n",
       "               '0312195516',\n",
       "               '0679444815',\n",
       "               '0805063897',\n",
       "               '0743203631',\n",
       "               '0345423291',\n",
       "               '0425188809',\n",
       "               '052594527X',\n",
       "               '0671041789',\n",
       "               '0767905385',\n",
       "               '1592400876',\n",
       "               '0767902521',\n",
       "               '0316781142',\n",
       "               '0446516570',\n",
       "               '0316789089',\n",
       "               '0380820145',\n",
       "               '0439136369',\n",
       "               '0671519816',\n",
       "               '0446519804',\n",
       "               '038531292X',\n",
       "               '0375726349',\n",
       "               '0446610038',\n",
       "               '0380725835',\n",
       "               '043935806X',\n",
       "               '0553272535',\n",
       "               '0590353403',\n",
       "               '0061000175',\n",
       "               '0316666009',\n",
       "               '038079487X',\n",
       "               '0060392452',\n",
       "               '0385498802',\n",
       "               '0385510438',\n",
       "               '0142001740',\n",
       "               '0316969680',\n",
       "               '0151008116',\n",
       "               '0451179803',\n",
       "               '0316154059',\n",
       "               '0425178951',\n",
       "               '0446679593',\n",
       "               '0553584480',\n",
       "               '0312421273',\n",
       "               '0399143947',\n",
       "               '0385508042',\n",
       "               '0515090506',\n",
       "               '0425190641',\n",
       "               '0553580388',\n",
       "               '0451208080',\n",
       "               '0060504110',\n",
       "               '0670032379',\n",
       "               '0061030597',\n",
       "               '0345447867',\n",
       "               '0786868716',\n",
       "               '0385721420',\n",
       "               '0425183971',\n",
       "               '0440998050',\n",
       "               '140003065X',\n",
       "               '0449223604',\n",
       "               '0385493800',\n",
       "               '0449002985',\n",
       "               '0609610597',\n",
       "               '0425168298',\n",
       "               '0316782505',\n",
       "               '1400031354',\n",
       "               '0446670251',\n",
       "               '0446530891',\n",
       "               '0310205719',\n",
       "               '0679746048',\n",
       "               '0425121259',\n",
       "               '0743436210',\n",
       "               '0446531332',\n",
       "               '0671525743',\n",
       "               '015602943X',\n",
       "               '0451207645',\n",
       "               '1551668912',\n",
       "               '0140254544',\n",
       "               '0743437802',\n",
       "               '0060580275',\n",
       "               '0802139256',\n",
       "               '0553578022',\n",
       "               '081297106X',\n",
       "               '0805059555',\n",
       "               '0399149155',\n",
       "               '0452264464',\n",
       "               '067102535X',\n",
       "               '0375413634'],\n",
       "              5: []}})"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_recommand"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 找到热门书籍"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['0971880107',\n",
       " '0316666343',\n",
       " '0385504209',\n",
       " '0060928336',\n",
       " '067976402X',\n",
       " '0312195516',\n",
       " '044023722X',\n",
       " '059035342X',\n",
       " '0679781587',\n",
       " '0142001740',\n",
       " '0375727345',\n",
       " '0446672211',\n",
       " '0671027360',\n",
       " '0804106304',\n",
       " '044021145X',\n",
       " '0060930535',\n",
       " '0440211727',\n",
       " '0312278586',\n",
       " '0345337662',\n",
       " '0452282152',\n",
       " '0316601950',\n",
       " '0446605239',\n",
       " '0440214041',\n",
       " '0743418174',\n",
       " '0671021001',\n",
       " '0345417623',\n",
       " '0440226430',\n",
       " '0345370775',\n",
       " '0446610038',\n",
       " '0156027321',\n",
       " '0440241073',\n",
       " '068484477X',\n",
       " '0446310786',\n",
       " '0440221471',\n",
       " '0060987103',\n",
       " '0440225701',\n",
       " '1400034779',\n",
       " '0440220602',\n",
       " '0440234743',\n",
       " '0312291639',\n",
       " '0316284955',\n",
       " '006101351X',\n",
       " '0140293248',\n",
       " '0440236673',\n",
       " '0671003755',\n",
       " '0385484518',\n",
       " '0375707972',\n",
       " '0345443284',\n",
       " '0440213525',\n",
       " '0375706771',\n",
       " '044022165X',\n",
       " '0060502258',\n",
       " '0345361792',\n",
       " '0316769487',\n",
       " '0440222656',\n",
       " '0440224764',\n",
       " '0345313860',\n",
       " '0786868716',\n",
       " '044651652X',\n",
       " '0385492081',\n",
       " '0446606812',\n",
       " '0380731851',\n",
       " '0684872153',\n",
       " '0316776963',\n",
       " '0446364193',\n",
       " '0385335482',\n",
       " '0060938455',\n",
       " '0060934417',\n",
       " '0060976845',\n",
       " '0345353145',\n",
       " '0440206154',\n",
       " '0671510053',\n",
       " '0439064872',\n",
       " '043935806X',\n",
       " '0385265700',\n",
       " '0345342968',\n",
       " '0452282829',\n",
       " '080410753X',\n",
       " '0743237188',\n",
       " '0553572997',\n",
       " '0375700757',\n",
       " '0446608955',\n",
       " '0316096199',\n",
       " '0312305060',\n",
       " '0060392452',\n",
       " '0385720106',\n",
       " '080410526X',\n",
       " '0345339681',\n",
       " '0345378490',\n",
       " '0449212602',\n",
       " '0060987561',\n",
       " '0679429220',\n",
       " '0312983271',\n",
       " '0449005615',\n",
       " '0380730138',\n",
       " '0842329129',\n",
       " '014028009X',\n",
       " '0375725784',\n",
       " '0061009059',\n",
       " '0553279912',\n",
       " '0375726403',\n",
       " '0440226104',\n",
       " '0553268880',\n",
       " '0380789035',\n",
       " '034540288X',\n",
       " '0440224675',\n",
       " '0345380371',\n",
       " '1558743669',\n",
       " '0805063897',\n",
       " '0804114986',\n",
       " '0446607657',\n",
       " '0060959037',\n",
       " '0142000205',\n",
       " '0440212561',\n",
       " '0345351525',\n",
       " '0446606189',\n",
       " '0312966970',\n",
       " '0345391055',\n",
       " '0312976275',\n",
       " '0671042858',\n",
       " '0446612790',\n",
       " '0553250426',\n",
       " '0425154092',\n",
       " '0440211263',\n",
       " '0385722206',\n",
       " '0060977493',\n",
       " '0446611212',\n",
       " '0446601241',\n",
       " '0345384466',\n",
       " '0316569321',\n",
       " '0684874350',\n",
       " '0345339703',\n",
       " '0345387651',\n",
       " '0140244824',\n",
       " '0446612545',\n",
       " '0380789019',\n",
       " '080411109X',\n",
       " '0449907481',\n",
       " '0060915544',\n",
       " '0679746048',\n",
       " '0440241537',\n",
       " '0449003795',\n",
       " '0061097101',\n",
       " '0440236703',\n",
       " '0515131229',\n",
       " '0553280341',\n",
       " '1573229326',\n",
       " '0671001795',\n",
       " '0385486804',\n",
       " '0062502182',\n",
       " '0671041789',\n",
       " '0609804138',\n",
       " '0439136350',\n",
       " '0553275976',\n",
       " '0439136369',\n",
       " '0767905180',\n",
       " '0425147622',\n",
       " '068484267X',\n",
       " '0316781266',\n",
       " '0446610399',\n",
       " '0312924585',\n",
       " '0425175405',\n",
       " '0345465083',\n",
       " '0671027387',\n",
       " '0440219078',\n",
       " '0425182908',\n",
       " '0767900383',\n",
       " '0425180638',\n",
       " '0312980140',\n",
       " '0312282990',\n",
       " '0553271636',\n",
       " '0425167313',\n",
       " '155874262X',\n",
       " '0440235162',\n",
       " '0385505833',\n",
       " '0842329218',\n",
       " '0671038184',\n",
       " '0684801523',\n",
       " '0345402871',\n",
       " '0385503822',\n",
       " '0440235596',\n",
       " '1400031354',\n",
       " '0060987529',\n",
       " '0151008116',\n",
       " '0399501487',\n",
       " '0451166892',\n",
       " '0671004530',\n",
       " '0385508042',\n",
       " '080411868X',\n",
       " '038079487X',\n",
       " '0446604666',\n",
       " '074343627X',\n",
       " '0553273914',\n",
       " '0446608815',\n",
       " '0140298479',\n",
       " '0140067477',\n",
       " '0553272535',\n",
       " '034538475X',\n",
       " '0439139597',\n",
       " '0312995423',\n",
       " '1573225789',\n",
       " '0767902521',\n",
       " '0380718340',\n",
       " '0425152251',\n",
       " '0449219364',\n",
       " '0553260111',\n",
       " '0312966091',\n",
       " '0385335881',\n",
       " '0439139600',\n",
       " '0380018179',\n",
       " '0345350499',\n",
       " '0446611867',\n",
       " '0345339711',\n",
       " '0375702709',\n",
       " '0345413903',\n",
       " '0425163407',\n",
       " '0515132020',\n",
       " '0446605484',\n",
       " '0446604801',\n",
       " '0515128546',\n",
       " '0684848783',\n",
       " '0380002930',\n",
       " '0070212570',\n",
       " '044651862X',\n",
       " '0064407667',\n",
       " '0446609404',\n",
       " '0312971346',\n",
       " '014029628X',\n",
       " '0066214122',\n",
       " '0671004573',\n",
       " '0425172546',\n",
       " '0451183665',\n",
       " '0345424719',\n",
       " '031242227X',\n",
       " '0385498802',\n",
       " '0671014196',\n",
       " '0515130389',\n",
       " '0452264464',\n",
       " '0345427637',\n",
       " '0449223612',\n",
       " '051513287X',\n",
       " '0375703063',\n",
       " '0786881852',\n",
       " '0451184963',\n",
       " '0553582755',\n",
       " '0425162443',\n",
       " '0743412028',\n",
       " '0060391626',\n",
       " '0439064864',\n",
       " '042516098X',\n",
       " '0449221482',\n",
       " '0385474016',\n",
       " '0553280368',\n",
       " '0451203771',\n",
       " '0312983867',\n",
       " '0140119906',\n",
       " '0449003787',\n",
       " '0440224624',\n",
       " '0553277472',\n",
       " '0385479565',\n",
       " '0812550706',\n",
       " '067102423X',\n",
       " '0446608890',\n",
       " '0446670251',\n",
       " '0446611085',\n",
       " '0451160525',\n",
       " '044022103X',\n",
       " '0804111359',\n",
       " '0142001805',\n",
       " '002542730X',\n",
       " '0553582747',\n",
       " '0385721420',\n",
       " '0679745203',\n",
       " '0786817070',\n",
       " '0515135062',\n",
       " '0345413350',\n",
       " '0142004235',\n",
       " '0451156609',\n",
       " '0440223202',\n",
       " '0451526341',\n",
       " '0440998050',\n",
       " '0553564528',\n",
       " '0451172817',\n",
       " '0425169863',\n",
       " '034541389X',\n",
       " '0425122123',\n",
       " '0553580221',\n",
       " '0385511612',\n",
       " '0425158616',\n",
       " '0316780375',\n",
       " '0451176464',\n",
       " '0060921145',\n",
       " '0446394521',\n",
       " '038572179X',\n",
       " '055356451X',\n",
       " '0141000198',\n",
       " '0451524934',\n",
       " '0553284789',\n",
       " '0375705856',\n",
       " '0441003257',\n",
       " '0345339738',\n",
       " '0553579606',\n",
       " '0449221512',\n",
       " '0671708635',\n",
       " '0515128554',\n",
       " '0060175400',\n",
       " '0449221504',\n",
       " '0380717018',\n",
       " '0345438329',\n",
       " '0515133973',\n",
       " '0749397543',\n",
       " '0345348036',\n",
       " '014025448X',\n",
       " '0380718332',\n",
       " '0425116840',\n",
       " '0440498058',\n",
       " '0671793489',\n",
       " '0425143325',\n",
       " '0679751521',\n",
       " '0671004565',\n",
       " '0786885688',\n",
       " '0786867647',\n",
       " '038550120X',\n",
       " '0375703055',\n",
       " '0743203631',\n",
       " '0452260116',\n",
       " '0446606324',\n",
       " '0316899984',\n",
       " '0802130208',\n",
       " '0446360589',\n",
       " '0671867156',\n",
       " '0515132187',\n",
       " '0440414806',\n",
       " '0441569595',\n",
       " '0380710218',\n",
       " '0679744398',\n",
       " '0553561618',\n",
       " '0345391802',\n",
       " '0316789089',\n",
       " '037570504X',\n",
       " '0449223604',\n",
       " '0060958022',\n",
       " '0743224574',\n",
       " '0345370805',\n",
       " '0345439104',\n",
       " '0451177096',\n",
       " '0060199652',\n",
       " '0451202341',\n",
       " '014023313X',\n",
       " '0553375407',\n",
       " '0099771519',\n",
       " '0671568175',\n",
       " '0446607711',\n",
       " '0064400557',\n",
       " '0515126772',\n",
       " '0425092917',\n",
       " '0440180295',\n",
       " '0671024248',\n",
       " '0142001430',\n",
       " '0399149155',\n",
       " '0679735909',\n",
       " '0679731148',\n",
       " '0743211375',\n",
       " '034543479X',\n",
       " '0553582135',\n",
       " '0553582127',\n",
       " '0425107469',\n",
       " '0451169530',\n",
       " '0671693816',\n",
       " '0553578693',\n",
       " '067088300X',\n",
       " '1559029838',\n",
       " '0425192725',\n",
       " '038533334X',\n",
       " '0452284449',\n",
       " '0345404114',\n",
       " '0374129983',\n",
       " '0061015725',\n",
       " '1558745157',\n",
       " '0871136791',\n",
       " '0440221595',\n",
       " '1400031362',\n",
       " '0312980159',\n",
       " '0312990456',\n",
       " '0316777730',\n",
       " '0316693200',\n",
       " '0671867172',\n",
       " '067976397X',\n",
       " '0743418204',\n",
       " '0316969680',\n",
       " '0553279378',\n",
       " '0446532231',\n",
       " '0451181379',\n",
       " '0688177751',\n",
       " '0671867113',\n",
       " '0385720955',\n",
       " '0373218036',\n",
       " '0743225406',\n",
       " '0446359866',\n",
       " '0553574574',\n",
       " '0553579754',\n",
       " '0767905385',\n",
       " '0425182878',\n",
       " '0679772677',\n",
       " '0446679593',\n",
       " '0553573136',\n",
       " '0671894455',\n",
       " '0312983824',\n",
       " '0446363251',\n",
       " '1878424319',\n",
       " '038529929X',\n",
       " '0451203895',\n",
       " '0446611808',\n",
       " '038542017X',\n",
       " '0671004107',\n",
       " '0312243022',\n",
       " '0743227441',\n",
       " '038550926X',\n",
       " '0345378482',\n",
       " '0449134482',\n",
       " '0671867091',\n",
       " '0345435168',\n",
       " '0385336179',\n",
       " '0345369947',\n",
       " '0451191145',\n",
       " '0385420161',\n",
       " '0330332775',\n",
       " '0515127833',\n",
       " '0060173289',\n",
       " '0375502238',\n",
       " '0553292722',\n",
       " '0671042262',\n",
       " '0425109720',\n",
       " '0553208845',\n",
       " '0553569910',\n",
       " '0671880314',\n",
       " '0743411250',\n",
       " '0385730586',\n",
       " '0312421273',\n",
       " '1558744150',\n",
       " '0385502532',\n",
       " '0451151259',\n",
       " '0440202043',\n",
       " '0446516538',\n",
       " '0425124347',\n",
       " '1592400876',\n",
       " '0452282195',\n",
       " '140003065X',\n",
       " '042511774X',\n",
       " '051512608X',\n",
       " '0316602051',\n",
       " '0684867621',\n",
       " '0671758896',\n",
       " '0553279556',\n",
       " '0590353403',\n",
       " '0842329242',\n",
       " '0449221490',\n",
       " '0440215625',\n",
       " '042510107X',\n",
       " '0425180964',\n",
       " '0345446860',\n",
       " '0552124753',\n",
       " '0451188454',\n",
       " '0451167317',\n",
       " '031298328X',\n",
       " '0679734775',\n",
       " '0671673688',\n",
       " '0671011367',\n",
       " '0385490992',\n",
       " '0060922532',\n",
       " '0061097314',\n",
       " '0375703861',\n",
       " '0743457358',\n",
       " '0446610542',\n",
       " '0312974256',\n",
       " '0684865742',\n",
       " '0451186362',\n",
       " '0345386108',\n",
       " '0786889020',\n",
       " '0425184226',\n",
       " '0743437640',\n",
       " '0316602906',\n",
       " '0446602620',\n",
       " '0671888587',\n",
       " '006016848X',\n",
       " '0316777722',\n",
       " '0373218400',\n",
       " '0671617028',\n",
       " '0441790348',\n",
       " '0553586122',\n",
       " '0316693006',\n",
       " '0743467523',\n",
       " '0440213290',\n",
       " '042513525X',\n",
       " '0553289411',\n",
       " '0316168815',\n",
       " '038549081X',\n",
       " '0842342702',\n",
       " '0345368754',\n",
       " '0425133540',\n",
       " '0679735771',\n",
       " '0446603589',\n",
       " '0671042572',\n",
       " '0515136379',\n",
       " '0553580191',\n",
       " '0385512104',\n",
       " '0670865796',\n",
       " '0449219461',\n",
       " '0385497466',\n",
       " '0802139256',\n",
       " '0156007754',\n",
       " '067100042X',\n",
       " '0679446486',\n",
       " '0446675059',\n",
       " '0553582526',\n",
       " '0425150143',\n",
       " '0786890436',\n",
       " '0316693235',\n",
       " '0671759345',\n",
       " '1551668998',\n",
       " '0446365505',\n",
       " '0670892963',\n",
       " '0688177859',\n",
       " '0441172717',\n",
       " '0399144463',\n",
       " '0316969443',\n",
       " '0553296981',\n",
       " '0440200563',\n",
       " '0399150897',\n",
       " '0804115761',\n",
       " '0156628708',\n",
       " '0451137965',\n",
       " '0553582143',\n",
       " '0452268060',\n",
       " '0446603716',\n",
       " '0345334531',\n",
       " '0399145087',\n",
       " '0553581554',\n",
       " '0515118656',\n",
       " '0553583980',\n",
       " '039592720X',\n",
       " '0679731725',\n",
       " '055321313X',\n",
       " '0515136530',\n",
       " '0553578022',\n",
       " '0452269571',\n",
       " '0553278029',\n",
       " '0446531332',\n",
       " '0743436210',\n",
       " '0679444815',\n",
       " '0399146431',\n",
       " '0425153975',\n",
       " '0373484003',\n",
       " '0446611778',\n",
       " '0385472951',\n",
       " '0312971125',\n",
       " '0743460529',\n",
       " '0553579983',\n",
       " '0316089699',\n",
       " '0451206525',\n",
       " '0156028778',\n",
       " '0345298349',\n",
       " '0440176484',\n",
       " '0375703764',\n",
       " '0671027344',\n",
       " '089480829X',\n",
       " '0060932759',\n",
       " '0446608602',\n",
       " '0553580930',\n",
       " '0515135739',\n",
       " '0452283205',\n",
       " '0446605409',\n",
       " '051513628X',\n",
       " '0451163524',\n",
       " '1400031346',\n",
       " '0374199698',\n",
       " '0373484410',\n",
       " '014038572X',\n",
       " '0671670689',\n",
       " '0449002632',\n",
       " '006099486X',\n",
       " '0316782505',\n",
       " '0425083837',\n",
       " '0446610100',\n",
       " '0609610597',\n",
       " '0671250671',\n",
       " '0345348109',\n",
       " '0553274295',\n",
       " '0671028375',\n",
       " '0525947647',\n",
       " '0425183971',\n",
       " '0316781010',\n",
       " '0345447840',\n",
       " '0330367358',\n",
       " '0425147517',\n",
       " '0425170349',\n",
       " '0380820293',\n",
       " '0380977788',\n",
       " '0439404371',\n",
       " '0425147363',\n",
       " '0670894605',\n",
       " '0842329250',\n",
       " '0312924801',\n",
       " '0385503954',\n",
       " '055356160X',\n",
       " '043936213X',\n",
       " '0140092323',\n",
       " '0091867770',\n",
       " '0316168688',\n",
       " '0385475721',\n",
       " '0451192001',\n",
       " '0375412824',\n",
       " '0446604844',\n",
       " '0425185710',\n",
       " '0425144429',\n",
       " '0553571885',\n",
       " '0385508417',\n",
       " '0345441036',\n",
       " '0552998486',\n",
       " '0425178102',\n",
       " '0684833395',\n",
       " '0553572326',\n",
       " '0552137030',\n",
       " '0385424728',\n",
       " '051512317X',\n",
       " '0446609943',\n",
       " '0440204887',\n",
       " '0553560247',\n",
       " '0449910237',\n",
       " '0441005489',\n",
       " '0425158632',\n",
       " '0425172996',\n",
       " '0449912558',\n",
       " '0446603929',\n",
       " '0440236738',\n",
       " '0671880187',\n",
       " '0373244487',\n",
       " '0399146253',\n",
       " '0425189864',\n",
       " '0345397819',\n",
       " '0345384350',\n",
       " '1558744630',\n",
       " '0804105820',\n",
       " '038082101X',\n",
       " '0373218192',\n",
       " '0446364800',\n",
       " '0140042598',\n",
       " '0312966806',\n",
       " '074322535X',\n",
       " '0345436911',\n",
       " '0380814021',\n",
       " '0061099708',\n",
       " '0451188462',\n",
       " '0425128164',\n",
       " '0684853515',\n",
       " '0373218397',\n",
       " '0385493800',\n",
       " '014100018X',\n",
       " '038531258X',\n",
       " '0373825013',\n",
       " '0316666009',\n",
       " '0671002481',\n",
       " '0440224705',\n",
       " '0446609323',\n",
       " '0060188731',\n",
       " '0425151875',\n",
       " '0449005836',\n",
       " '0380012863',\n",
       " '0140185216',\n",
       " '0441304834',\n",
       " '0375727132',\n",
       " '0060929871',\n",
       " '0375705198',\n",
       " '1573227331',\n",
       " '0399141146',\n",
       " '0786866586',\n",
       " '0140179836',\n",
       " '0446611611',\n",
       " '0446525502',\n",
       " '0425121631',\n",
       " '0679723161',\n",
       " '0385510438',\n",
       " '0515124214',\n",
       " '0375706410',\n",
       " '0312982518',\n",
       " '0312422156',\n",
       " '0061000175',\n",
       " '0449203794',\n",
       " '0425147584',\n",
       " '080411918X',\n",
       " '0671789422',\n",
       " '055357230X',\n",
       " '0670880728',\n",
       " '076790592X',\n",
       " '0553576801',\n",
       " '0451153553',\n",
       " '0671026011',\n",
       " '0425126064',\n",
       " '042513699X',\n",
       " '0553801430',\n",
       " '0553578685',\n",
       " '038542471X',\n",
       " '0553569031',\n",
       " '0451169522',\n",
       " '0515124893',\n",
       " '0345354613',\n",
       " '0553263226',\n",
       " '0671525743',\n",
       " '0804106436',\n",
       " '1573221937',\n",
       " '0316781142',\n",
       " '042518630X',\n",
       " '0060740450',\n",
       " '034539657X',\n",
       " '0316182540',\n",
       " '0385472943',\n",
       " '0440224594',\n",
       " '0553282476',\n",
       " '0425118703',\n",
       " '0743437802',\n",
       " '0515120618',\n",
       " '0440224845',\n",
       " '0671741187',\n",
       " '0399149325',\n",
       " '0812511816',\n",
       " '0394820371',\n",
       " '0425155404',\n",
       " '0425132048',\n",
       " '0425189031',\n",
       " '0446530522',\n",
       " '0553571818',\n",
       " '0671036505',\n",
       " '0679441018',\n",
       " '0425115801',\n",
       " '0515130966',\n",
       " '0099387913',\n",
       " '0553210092',\n",
       " '0452280621',\n",
       " '0375413634',\n",
       " '0451180232',\n",
       " '1573229571',\n",
       " '0316788228',\n",
       " '0151002290',\n",
       " '0312979096',\n",
       " '0375504397',\n",
       " '0553211404',\n",
       " '0451207521',\n",
       " '0804108749',\n",
       " '0440217563',\n",
       " '034538184X',\n",
       " '0670030643',\n",
       " '0312265867',\n",
       " '1551669498',\n",
       " '0345435796',\n",
       " '0425121259',\n",
       " '0446613266',\n",
       " '0310205719',\n",
       " '0440203856',\n",
       " '0399143947',\n",
       " '0451170385',\n",
       " '0446520802',\n",
       " '0679433740',\n",
       " '0553250531',\n",
       " '0553578316',\n",
       " '0380727501',\n",
       " '081297106X',\n",
       " '0671027662',\n",
       " '1565122968',\n",
       " '1558745718',\n",
       " '0552996009',\n",
       " '0345413873',\n",
       " '0345404769',\n",
       " '080213825X',\n",
       " '0312986343',\n",
       " '0805059555',\n",
       " '080411935X',\n",
       " '0061099732',\n",
       " '0553280414',\n",
       " '0425177173',\n",
       " '051512219X',\n",
       " '0380973545',\n",
       " '0373484429',\n",
       " '0373243790',\n",
       " '0061020710',\n",
       " '1573228214',\n",
       " '0671727796',\n",
       " '0440217490',\n",
       " '0312978383',\n",
       " '0451163966',\n",
       " '0553583468',\n",
       " '0345422317',\n",
       " '0553573209',\n",
       " '034536676X',\n",
       " '0345445848',\n",
       " '0425179613',\n",
       " '0446604275',\n",
       " '055358264X',\n",
       " '0060008032',\n",
       " '0399147195',\n",
       " '0440204194',\n",
       " '0553578308',\n",
       " '0446519138',\n",
       " '0373250126',\n",
       " '0515133302',\n",
       " '0451197747',\n",
       " '0385424736',\n",
       " '0805062971',\n",
       " '0345384369',\n",
       " '0060926317',\n",
       " '0316693251',\n",
       " '0688170528',\n",
       " '8873122933',\n",
       " '0140254544',\n",
       " '0451205421',\n",
       " '0449910571',\n",
       " '0312978367',\n",
       " '0670805149',\n",
       " '055357227X',\n",
       " '0671683993',\n",
       " '0345441133',\n",
       " '067101420X',\n",
       " '0425161242',\n",
       " '0425158640',\n",
       " '0316603287',\n",
       " '0679448594',\n",
       " '0743417682',\n",
       " '067164257X',\n",
       " '0446527793',\n",
       " '0553213105',\n",
       " '0671864173',\n",
       " '0440241413',\n",
       " '0451180429',\n",
       " '0345314255',\n",
       " '0446343455',\n",
       " '0441783589',\n",
       " '0553572202',\n",
       " '006109921X',\n",
       " '0874776945',\n",
       " '0670878847',\n",
       " '0380778556',\n",
       " '0553569155',\n",
       " '0375504613',\n",
       " '0671886665',\n",
       " '0590660543',\n",
       " '0553574663',\n",
       " '0425178765',\n",
       " '0440207770',\n",
       " '0679459618',\n",
       " '0375506039',\n",
       " '0671527215',\n",
       " '0425145638',\n",
       " '0374100128',\n",
       " '0425151867',\n",
       " '0425165701',\n",
       " '0553213148',\n",
       " '0440122090',\n",
       " '0671028367',\n",
       " '0553582763',\n",
       " '0425163385',\n",
       " '0425100650',\n",
       " '0449227545',\n",
       " '0671743058',\n",
       " '0553575104',\n",
       " '0440439884',\n",
       " '044011585X',\n",
       " '0553380095',\n",
       " '0452281903',\n",
       " '0061000043',\n",
       " '0553582658',\n",
       " '055328942X',\n",
       " '0399141464',\n",
       " '0060096195',\n",
       " '0553264079',\n",
       " '0767905202',\n",
       " '0425167720',\n",
       " '0515122734',\n",
       " '015100692X',\n",
       " '0375412530',\n",
       " '0553568760',\n",
       " '0373483503',\n",
       " '0425168298',\n",
       " '034540761X',\n",
       " '0425132951',\n",
       " '0385720920',\n",
       " '0553576798',\n",
       " '0425146413',\n",
       " '0515120006',\n",
       " '0812550757',\n",
       " '0743439740',\n",
       " '0553576089',\n",
       " '0312244266',\n",
       " '0525947299',\n",
       " '0671024094',\n",
       " '0312150601',\n",
       " '0805063889',\n",
       " '0553274503',\n",
       " '042517736X',\n",
       " '0440213029',\n",
       " '0425140032',\n",
       " '051511992X',\n",
       " '0385335830',\n",
       " '0860074382',\n",
       " '0842329269',\n",
       " '0312979479',\n",
       " '0061096113',\n",
       " '0446670111',\n",
       " '0316779423',\n",
       " '0451191153',\n",
       " '1573225517',\n",
       " '0312274920',\n",
       " '0446608653',\n",
       " '0553802496',\n",
       " '0425192733',\n",
       " '0345362861',\n",
       " '0553573403',\n",
       " '0446604402',\n",
       " '0312983298',\n",
       " '0316603570',\n",
       " '0515132136',\n",
       " '0061098795',\n",
       " '0552999458',\n",
       " '0440108268',\n",
       " '0553560735',\n",
       " '0804114609',\n",
       " '1558743316',\n",
       " '0767902890',\n",
       " '0743235150',\n",
       " '0425133516',\n",
       " '0446604232',\n",
       " '0446604658',\n",
       " '0449149676',\n",
       " '0446350982',\n",
       " '0440207622',\n",
       " '157322930X',\n",
       " '0446613436',\n",
       " '0451410947',\n",
       " '0385315236',\n",
       " '0061091790',\n",
       " '0671004549',\n",
       " '0385729332',\n",
       " '0345303067',\n",
       " '0786861347',\n",
       " '0345413865',\n",
       " '0380730847',\n",
       " '0140177396',\n",
       " '0553569058',\n",
       " '0440221099',\n",
       " '0330267388',\n",
       " '0446608262',\n",
       " '0671701231',\n",
       " '0446530077',\n",
       " '0552998001',\n",
       " '0767915054',\n",
       " '0099747200',\n",
       " '0060916508',\n",
       " '0451204530',\n",
       " '0425191184',\n",
       " '0345447867',\n",
       " '0345392825',\n",
       " '042518286X',\n",
       " '0679405283',\n",
       " '0140280553',\n",
       " '0446673544',\n",
       " '000649840X',\n",
       " '1558531025',\n",
       " '0671000314',\n",
       " '0446527785',\n",
       " '0440224780',\n",
       " '0451190491',\n",
       " '0440183057',\n",
       " '0440967694',\n",
       " '0812570944',\n",
       " '0373250282',\n",
       " '0425181103',\n",
       " '0345422384',\n",
       " '0525946829',\n",
       " '0515130044',\n",
       " '0312201656',\n",
       " '0385324057',\n",
       " '0671014919',\n",
       " '0345396936',\n",
       " '0399148027',\n",
       " '0440178002',\n",
       " '0553096060',\n",
       " '0345453816',\n",
       " '0425155722',\n",
       " '0449911004',\n",
       " '0684835983',\n",
       " '0446519081',\n",
       " '044022425X',\n",
       " '0553258001',\n",
       " '0515134384',\n",
       " '0425161722',\n",
       " '0440514428',\n",
       " '0440201926',\n",
       " '0446527165',\n",
       " '044900371X',\n",
       " '044661064X',\n",
       " '0553584510',\n",
       " '0553299506',\n",
       " ...]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "top2000_item_id_s = df_data_training['item_id'].value_counts()[:2000].index.tolist()\n",
    "top2000_item_id_s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>location</th>\n",
       "      <th>age</th>\n",
       "      <th>item_id</th>\n",
       "      <th>rating</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>182843</th>\n",
       "      <td>42721</td>\n",
       "      <td>canada</td>\n",
       "      <td>3</td>\n",
       "      <td>0671024108</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80014</th>\n",
       "      <td>19842</td>\n",
       "      <td>usa</td>\n",
       "      <td>0</td>\n",
       "      <td>0446603392</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>714705</th>\n",
       "      <td>175003</td>\n",
       "      <td>usa</td>\n",
       "      <td>3</td>\n",
       "      <td>0316601950</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>514144</th>\n",
       "      <td>126911</td>\n",
       "      <td>usa</td>\n",
       "      <td>4</td>\n",
       "      <td>0345335465</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3503</th>\n",
       "      <td>1519</td>\n",
       "      <td>usa</td>\n",
       "      <td>4</td>\n",
       "      <td>0671028375</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        user_id location  age     item_id  rating\n",
       "182843    42721   canada    3  0671024108       8\n",
       "80014     19842      usa    0  0446603392       0\n",
       "714705   175003      usa    3  0316601950       0\n",
       "514144   126911      usa    4  0345335465       0\n",
       "3503       1519      usa    4  0671028375       8"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_data_training_top2000 = df_data_training[\n",
    "    df_data_training['item_id'].isin(top2000_item_id_s)\n",
    "]\n",
    "df_data_training_top2000.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Int64Index: 69313 entries, 182843 to 473426\n",
      "Data columns (total 5 columns):\n",
      " #   Column    Non-Null Count  Dtype \n",
      "---  ------    --------------  ----- \n",
      " 0   user_id   69313 non-null  int64 \n",
      " 1   location  69313 non-null  object\n",
      " 2   age       69313 non-null  int64 \n",
      " 3   item_id   69313 non-null  object\n",
      " 4   rating    69313 non-null  int64 \n",
      "dtypes: int64(3), object(2)\n",
      "memory usage: 3.2+ MB\n"
     ]
    }
   ],
   "source": [
    "df_data_training_top2000.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['0590353403',\n",
       " '0446677450',\n",
       " '0439064864',\n",
       " '0439136369',\n",
       " '043935806X',\n",
       " '0740704818',\n",
       " '0618002227',\n",
       " '0439136350',\n",
       " '0060175966',\n",
       " '0064471101',\n",
       " '0439139597',\n",
       " '0316154059',\n",
       " '0679775439',\n",
       " '0393317552',\n",
       " '0553573403',\n",
       " '0553213695',\n",
       " '0156528207',\n",
       " '0440229499',\n",
       " '0894808249',\n",
       " '0552131067']"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "top20_item_id_s = df_data_training_top2000.groupby('item_id')['rating'].mean().sort_values(ascending=False)[:20].index.tolist()\n",
    "top20_item_id_s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "for location in feature_recommand.keys():\n",
    "    for age in feature_recommand[location].keys():\n",
    "        feature_recommand_len = len(feature_recommand[location][age])\n",
    "        feature_recommand[location][age] += top20_item_id_s[:20-feature_recommand_len]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "cPickle.dump(feature_recommand,open('./data/feature_recommand.pkl','wb'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
